package utils

import (
	"strconv"
	"strings"
)

func To_cpu_h(s string) float64 {

	if strings.HasSuffix(s, "n") {
		i, _ := strconv.Atoi(strings.Replace(s, "n", "", -1))
		return float64(i) / 1000000000.00
	}
	if strings.HasSuffix(s, "m") {
		i, _ := strconv.Atoi(strings.Replace(s, "m", "", -1))
		return float64(i) / 1000.00
	}
	if strings.HasSuffix(s, "M") {
		i, _ := strconv.Atoi(strings.Replace(s, "M", "", -1))
		return float64(i) / 1024.00
	}

	i,_ :=strconv.Atoi(s)
	return float64(i)
}

func To_memory_g(s string) float64 {
	if strings.HasSuffix(s, "Ki") {
		i, _ := strconv.Atoi(strings.Replace(s, "Ki", "", -1))
		return float64(i) / 1000000.00
	}
	if strings.HasSuffix(s, "K") {
		i, _ := strconv.Atoi(strings.Replace(s, "K", "", -1))
		return float64(i) / 1024.00 / 1024.00
	}
	if strings.HasSuffix(s, "m") {
		i, _ := strconv.Atoi(strings.Replace(s, "m", "", -1))
		return float64(i) / 1000.00 / 1024.00 /1024.00 / 1024.00
	}
	if strings.HasSuffix(s, "M") {
		i, _ := strconv.Atoi(strings.Replace(s, "M", "", -1))
		return float64(i) / 1024.00
	}
	if strings.HasSuffix(s, "Mi") {
		i, _ := strconv.Atoi(strings.Replace(s, "Mi", "", -1))
		return float64(i) / 1000.00
	}
	if strings.HasSuffix(s, "Gi") {
		i, _ := strconv.Atoi(strings.Replace(s, "Gi", "", -1))
		return float64(i) / 1.00
	}
	if strings.HasSuffix(s, "G") {
		i, _ := strconv.Atoi(strings.Replace(s, "G", "", -1))
		return float64(i) / 1.00
	}
	i,_ :=strconv.Atoi(s)
	return float64(i) / 1024.00 / 1024.00 / 1024.00
}
